package anc.tankshooter.ui;

import org.andengine.engine.Engine;
import org.andengine.ui.IGameInterface.OnCreateSceneCallback;

public class SceneManager
{
	public enum SceneType
    {
        SCENE_SPLASH,
        SCENE_MENU,
        SCENE_SELECTLEVEL,
        SCENE_GAME,
        SCENE_LOGIN
    }
	
    private static final SceneManager instance = new SceneManager();
    private Engine mEngine;
    private OnCreateSceneCallback mCallback;
    private IScreen mCurrentScene;
    
    private SceneManager() {
    	mEngine = ResourcesManager.getInstance().mEngine;
    }
  
    public void setScene(IScreen scene)
    {
    	if(mCurrentScene!=null){
    		
    		if(mCurrentScene.getSceneType()!=null){
    			switch(mCurrentScene.getSceneType()){
        		case SCENE_SPLASH:
        			ResourcesManager.getInstance().unloadSplashScreen();
        			break;
        		case SCENE_MENU:
        			ResourcesManager.getInstance().unloadMenuResources();
        			break;
        		case SCENE_GAME:
        			ResourcesManager.getInstance().unloadGameResources();
        			break;
        		}
    		}
    		mCurrentScene.disposeScene();
    		mCurrentScene.dispose();
    	}
        mEngine.setScene(scene);
        mCurrentScene = scene;
        mCallback.onCreateSceneFinished(mCurrentScene);
    }
   
    //---------------------------------------------
    // GETTERS AND SETTERS
    //---------------------------------------------
    public IScreen getCurrentScene()
    {
        return mCurrentScene;
    }
    
    public void setCallback(OnCreateSceneCallback callback){
    	this.mCallback=callback;
    }

    public static SceneManager getInstance()
    {
        return instance;
    }
}